package com.pro.control;

import com.pro.dao.CourseRecordMapper;
import com.pro.entity.*;
import com.pro.service.CourseRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 笑笑
 * @create 2021/11/4下午 04:05
 */
@RestController
@RequestMapping("/CourseRecord")
public class CourseRecordController {
    @Autowired
    private CourseRecordService courseRecordService;
    @Autowired
    private CourseRecordMapper courseRecordMapper;

    //查询所有商品或视频的审核记录
    @RequestMapping("/getAllCourseRecord")
    public JsonData getAllCourseRecord(ProductPlus productPlus) {
        List<ProductPlus> allCourseRecord = courseRecordService.getAllCourseRecord(productPlus);
        return allCourseRecord.size() > 0 ? JsonData.buildSuccess(allCourseRecord) : JsonData.buildError("服务器端错误");
    }

    //查询所有商品或视频的审核记录个数
    @RequestMapping("/getAllNum")
    public JsonData getAllNum(Integer type) {
        Integer allNum = courseRecordMapper.getAllNum(type);
        return allNum != null ? JsonData.buildSuccess(allNum) : JsonData.buildError("服务器错误");
    }

    //查询所有商品或视频的代审核个数
    @RequestMapping("/getNumYes")
    public JsonData getNumYes(Integer type) {
        Integer allNum = courseRecordMapper.getNumYes(type);
        return allNum != null ? JsonData.buildSuccess(allNum) : JsonData.buildError("服务器错误");
    }

    //查询所有商品或视频的审核通过个数
    @RequestMapping("/getNum")
    public JsonData getNum(Integer type) {
        Integer allNum = courseRecordMapper.getNum(type);
        return allNum != null ? JsonData.buildSuccess(allNum) : JsonData.buildError("服务器错误");
    }

    //查询所有商品或视频的审核未通过个数
    @RequestMapping("/getNumNo")
    public JsonData getNumNo(Integer type) {
        Integer allNum = courseRecordMapper.getNumNo(type);
        return allNum != null ? JsonData.buildSuccess(allNum) : JsonData.buildError("服务器错误");
    }

    //修改
    @RequestMapping("/updateCourseRecord")
    public JsonData updateCourseRecord(CourseRecord courseRecord) {
        boolean b = false;
        try {
            b = courseRecordService.updateCourseRecord(courseRecord);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return b ? JsonData.buildSuccess(b) : JsonData.buildError("服务器错误");
    }


    //查询所有课程的审核记录
    @RequestMapping("/getAllCourse")
    public JsonData getAllCourse(CoursePlus coursePlus) {
        List<CoursePlus> allCourse = courseRecordService.getAllCourse(coursePlus);
        return allCourse.size() > 0 ? JsonData.buildSuccess(allCourse) : JsonData.buildError("没有查到");
    }

    //查询所有微圈的审核记录
    @RequestMapping("/getAllMicroCircle")
    public JsonData getAllMicroCircle(JsMicrocirclePlus jsMicrocirclePlus) {
        List<JsMicrocirclePlus> allCourse = courseRecordService.getAllMicroCircle(jsMicrocirclePlus);
        return allCourse.size() > 0 ? JsonData.buildSuccess(allCourse) : JsonData.buildError("没有查到");
    }

    //根据微圈id查询信息
    @RequestMapping("/getById")
    public JsonData getById(Integer microcircleId) {
        JsMicrocirclePlus byid = null;
        try {
            byid = courseRecordService.getById(microcircleId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return byid != null ? JsonData.buildSuccess(byid) : JsonData.buildError("没有查到");
    }
}
